package com.sgu6.redis;

import android.util.Log;

import com.sgu6.app.redis.RedisPoolConfig;
import com.sgu6.app.redis.RedisProviderFactory;
import com.sgu6.app.redis.RedisProviderInitializer;
import com.sgu6.redis.common.Constant;

public class RedisClient {

    protected static final String TAG = RedisClient.class.getSimpleName();

    public static void init(String uri) {
        try {
            //加载redis池
            RedisPoolConfig redisPoolConfig = new RedisPoolConfig();
            redisPoolConfig.setMinIdle(Constant.REDIS_MIN_IDLE);
            redisPoolConfig.setMaxIdle(Constant.REDIS_MAX_IDLE);
            redisPoolConfig.setMaxTotal(Constant.REDIS_MAX_TOTAL);
            redisPoolConfig.setJmxEnabled(false); //不添加会报错，安卓不支持jmx
            redisPoolConfig.setMaxWaitMillis(Constant.REDIS_MAX_WAIT_TIME);
            RedisProviderInitializer redisProviderInitializer = new RedisProviderInitializer(Constant.REDIS_MODE, Constant.REDIS_CONNECT_TIMEOUT, uri, redisPoolConfig);
            RedisProviderFactory.setRedisProvider(redisProviderInitializer.registerRedisProvier());
        } catch (Exception e) {
            Log.i(TAG, "static initializer: ");
        }
    }
}
